/*
 * @Author: 吴世扬 18368095041@163.com
 * @Date: 2022-11-15 17:07:20
 * @LastEditors: 吴世扬 18368095041@163.com
 * @LastEditTime: 2022-11-15 17:08:26
 * @FilePath: /vue3-datav/src/components/ui/OlMap/mixin/fitView.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { boundingExtent } from 'ol/extent';
export default {
    watch: {
        fitPointsData: {
            handler() {
                this.$nextTick(() => {
                    this.fitView();
                });
            },
            deep: true,
            immediate: true
        }
    },
    methods: {
        fitView() {
            if (this.fitPointsData.length > 0) {
                const extend = boundingExtent(
                    this.fitPointsData.map((item) => [item.lng, item.lat])
                );
                this.view.fit(extend, { nearest: true });
            }
        }
    }
};
